import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sprintf/sprintf.dart';
import 'package:xingsu/widget/hud.dart';

class EditUserViewModel extends GetxController {
  final TextEditingController nicknameController =
      TextEditingController(text: "卡卡林");
  final birthday = "".obs;
  final pic = "".obs;

  void saveClick() {
    HUD.show();
    Future.delayed(const Duration(seconds: 1), () {
      HUD.hide();
      Get.back();
    });
  }

  void chooseBirthday() {
    showDatePicker(
            context: Get.context!,
            initialDate: DateTime(2000),
            firstDate: DateTime(1900),
            lastDate: DateTime.now())
        .then((value) {
      if (value == null) return;
      birthday.value =
          sprintf("%04d-%02d-%02d", [value.year, value.month, value.day]);
    });
  }

  void choosePic() async {
    final ImagePicker _picker = ImagePicker();
    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
    if (image == null) return;
    pic.value = image.path;
  }
}
